package com.gem.mapper;

import com.gem.domain.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: 玲
 * @Description:
 * @create 2019-10-19 15:31
 * @Modified By:
 */
public interface CoreMapper {


    @Select("select * from core_event")
    List<CoreEvent> findCoreEvents();

    //已用
    @Select("select * from core_event where campus_id = #{campusId}  and core_event_status > 0")
    List<CoreEvent> findEventById(Integer campusId);

    Integer saveEvent(CoreEvent coreEvent);

    Integer savePlan(CorePlan corePlan);

    @Select("select * from campus where campus_id = #{campusId} and campus_status > 0")
    Campus findCampus(Integer campusId);

    Integer updateComplete(CoreEvent coreEvent);

    @Select("select * from core_event where core_event_name = #{eventName} and campus_id = #{campusId} and core_event_status > 0")
    List<CoreEvent> findEventsByName(@Param("eventName") String eventName, @Param("campusId") Integer campusId);

    @Update("update core_event set core_event_status = -1 where core_event_id = #{coreEventId}")
    Integer deleteById(@Param("coreEventId") Integer coreEventId);

    Integer deleteAll(int[] coreEventIds);

    @Select("select * from core_event where core_event_id = #{coreEventId}")
    CoreEvent findById(Integer coreEventId);

    @Select("select distinct core_group from core_event where campus_id = #{campusId} and core_event_status > 0")
    List<String> findGroup(Integer campusId);

    @Select("select * from core_event where core_group = #{gid}  and core_event_status > 0")
    List<CoreEvent> findByGid(String gid);

    @Select("select * from core_event where core_event_status > 0")
    List<CoreEvent> findAll();

    @Update("update core_event set core_event_status = -1 where core_group = #{gid}")
    Integer deleteByGid(String gid);

    Integer deleteGAll(String[] gids);

    @Select("select count(0) from core_event where complete_time is not null and campus_id in(select c.campus_id from campus c where market_employee_id = #{uid}) and core_event_status > 0")
    Integer countEvent(Integer uid);

    @Select("select count(0) from core_event where core_event_name = #{eventName} and complete_time is not null and campus_id in(select c.campus_id from campus c where market_employee_id = #{uid}) and core_event_status > 0")
    Integer countName(@Param("eventName") String eventName, @Param("uid") Integer uid);

    @Select("select count(0) from core_event where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(complete_time) and campus_id in(select c.campus_id from campus c where market_employee_id = #{uid}) and core_event_status > 0")
    Integer countEventWeek(Integer uid);

    @Select("select count(0) from core_event where core_event_name = #{eventName} and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(complete_time) and campus_id in(select c.campus_id from campus c where market_employee_id = #{uid}) and core_event_status > 0")
    Integer countNameWeek(Integer uid, String eventName);
}
